﻿#include "video_widget.h"
#include <grid_manager.h>
#include "interface/yinshu.h"
//构造函数
VideoWidget::VideoWidget(GridManager* gridMgr)
    : QFrame(gridMgr->parent()), _hasVideo(false), _gridLayout(gridMgr->grid()),_gridManager(gridMgr)
{
    //设置边框
  setFrameStyle(QFrame::Box);
  setLineWidth(2);
  setMidLineWidth(0);
  //黑底
  setStyleSheet("QFrame { background-color: black; }");

    //设置布局
  QVBoxLayout *layout = new QVBoxLayout(this);
  layout->setContentsMargins(0, 0, 0, 0);
  layout->setSpacing(0);
  //设置标签
  _label = new QLabel("Grid Widget", this);
  _label->setAlignment(Qt::AlignCenter);
  _label->setStyleSheet("QLabel { color: white; font-size: 16px; }");
  layout->addWidget(_label);
}
void VideoWidget::showWindow(bool show){
  if(show)
    this->show();
  else
    this->hide();

}
void VideoWidget::reset()
{
  _hasVideo = false;
  _label->show();
}
void VideoWidget::setPeerId(std::string peerId){
  _peerId=peerId;
  _label->setText(QString(_peerId.c_str()));
}

void VideoWidget::setHasVideo(bool hasVideo)
{
  _hasVideo = hasVideo;
  _hasVideo?_label->show():_label->hide();
}

//视频控件
void VideoWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
    void* handle=_gridManager->handle();
    if (!_isFullScreen)
    {
        _gridManager->showWindow(this,false);
        // 缩放到全屏
        _isFullScreen = true;
        //设置为高分辨率
        if(this->_peerId!="")
          SetMemberVideoProfile(handle,this->_peerId.c_str(),"high");
    }
    else
    {
        // 恢复到之前状态
        _isFullScreen = false;
        _gridManager->showWindow(this,true);
        //设置为高分辨率
        if(this->_peerId!="")
          SetMemberVideoProfile(handle,this->_peerId.c_str(),"low");
    }
}
